package com.game.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

@Component
public class RedisClient {
	private static final Logger log = LoggerFactory.getLogger(RedisClient.class);
	@Autowired
	private JedisPool jedisPool;

	public void set(String key, String value) {
		Jedis jedis = null;
		try {
			jedis = jedisPool.getResource();
			jedis.set(key, value);
		} catch(Exception ex){
			log.error("jedis错误:",ex);
		}
		finally {
			// 返还到连接池
			jedis.close();
		}
	}

	public String get(String key){

		Jedis jedis = null;
		try {
			jedis = jedisPool.getResource();
			return jedis.get(key);
		} finally {
			// 返还到连接池
			jedis.close();
		}
	}
	
	
}
